package o2o.utils.bankCardCheck;

import com.google.gson.Gson;
import com.wxapi.WxApiCall.WxApiCall;
import com.wxapi.model.RequestModel;
import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ${wushenglu} on 2018/6/11.
 */
public class BackCardCheckUtil {


    private static Map<String, Object> QryBankCardBy4_bak(String accountNo, String name, String idCardCode, String bankPreMobile) {
        RequestModel model = new RequestModel();
        model.setGwUrl("https://way.jd.com/youhuoBeijing/QryBankCardBy4");
        model.setAppkey("6d8511683b6c2906c8a024cb15a6fa8b");

        Map queryMap = new HashMap();
        queryMap.put("accountNo", accountNo); //访问参数 银行卡号
        queryMap.put("name", name); //访问参数   用户名称
        queryMap.put("idCardCode", idCardCode); //访问参数   身份证
        queryMap.put("bankPreMobile", bankPreMobile); //访问参数  持卡人手机号
        model.setQueryParams(queryMap);
        WxApiCall call = new WxApiCall();
        call.setModel(model);
        JSONObject result = JSONObject.fromObject(call.request());
        JSONObject result1 = JSONObject.fromObject(result.get("result").toString());
        JSONObject backCard = JSONObject.fromObject(result1.get("result").toString());
        return backCard;

    }

    // 校验银行卡是否正确
    public static BackCardCheckResult QryBankCardBy4(String accountNo, String name, String idCardCode, String bankPreMobile) {
        RequestModel model = new RequestModel();
        model.setGwUrl("https://way.jd.com/youhuoBeijing/QryBankCardBy4");
        model.setAppkey("6d8511683b6c2906c8a024cb15a6fa8b");

        Map queryMap = new HashMap();
        queryMap.put("accountNo", accountNo); //访问参数 银行卡号
        queryMap.put("name", name); //访问参数   用户名称
        queryMap.put("idCardCode", idCardCode); //访问参数   身份证
        queryMap.put("bankPreMobile", bankPreMobile); //访问参数  持卡人手机号
        model.setQueryParams(queryMap);
        WxApiCall call = new WxApiCall();
        call.setModel(model);
        JSONObject result = JSONObject.fromObject(call.request());
        if (null == result) {
            return null;
        }
        JSONObject result1 = JSONObject.fromObject(result.get("result").toString());
//        JSONObject backCard = JSONObject.fromObject(result1.get("result").toString());
        if (null == result1) {
            return null;
        }

        BackCardCheckResult backCardCheckResult = new Gson().fromJson(result1.get("result").toString(), BackCardCheckResult.class);
        return backCardCheckResult;
    }

    // 校验银行卡是否正确
    public static BackCardCheckResult QryBankCardBy3(String accountNo, String name, String idCardCode) {
        RequestModel model = new RequestModel();
        model.setGwUrl("https://way.jd.com/youhuoBeijing/Bankcard3");
        model.setAppkey("6d8511683b6c2906c8a024cb15a6fa8b");

        Map queryMap = new HashMap();
        queryMap.put("accountNo", accountNo); //访问参数 银行卡号
        queryMap.put("name", name); //访问参数   用户名称
        queryMap.put("idCardCode", idCardCode); //访问参数   身份证
        model.setQueryParams(queryMap);
        WxApiCall call = new WxApiCall();
        call.setModel(model);
        JSONObject result = JSONObject.fromObject(call.request());
        if (null == result) {
            return null;
        }
        JSONObject result1 = JSONObject.fromObject(result.get("result").toString());
//        JSONObject backCard = JSONObject.fromObject(result1.get("result").toString());
        if (null == result1) {
            return null;
        }

        BackCardCheckResult backCardCheckResult = new Gson().fromJson(result1.get("result").toString(), BackCardCheckResult.class);
        return backCardCheckResult;
    }


    public static void main(String[] args) {
//        RequestModel to = new RequestModel();
//        to.setGwUrl("https://way.jd.com/youhuoBeijing/QryBankCardBy4");
//        to.setAppkey("6d8511683b6c2906c8a024cb15a6fa8b");
//        Map queryMap = new HashMap();
//        queryMap.put("accountNo", "6230200060984130"); //访问参数
//        queryMap.put("name", "杨丽丽"); //访问参数
//        queryMap.put("idCardCode", "370983199202243228"); //访问参数
//        queryMap.put("bankPreMobile", "18765878298"); //访问参数
//        to.setQueryParams(queryMap);
//        WxApiCall call = new WxApiCall();
//        call.setModel(to);
//        System.out.println(call.request());
//        JSONObject result = JSONObject.fromObject(call.request());
//        JSONObject result1 = JSONObject.fromObject(result.get("result").toString());
//        JSONObject backCard = JSONObject.fromObject(result1.get("result").toString());
//        System.out.println(backCard.toString());
//        System.out.println(QryBankCardBy4("6216690600000323533", "杨春颖", "222403197903287440", "15943344379").getResult());
//        System.out.println(QryBankCardBy3("6216690600000323533", "杨春颖", "222403197903287440").getResult());

//	“T”表示有效的，”F”表示无效的，“N”表示无法认证的，”P”表示网络连接超时


    }
}
